<?php

/**
 * estudiantesasignados actions.
 *
 * @package    atenea
 * @subpackage estudiantesasignados
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class estudiantesasignadosActions extends autoestudiantesasignadosActions
{

  public function executeIndex()
  {
    return $this->forward('estudiantesasignados', 'list');
  }

  public function executeList()
  {
  //  $this->processSort();

  //  $this->processFilters();


    // pager
    $idP = $this->getUser()->getAttribute('idP');
    $this->pager = new sfPropelPager('AsignarEst', 20);
    $c = new Criteria();
    $c->add(AsignarEstPeer::PROFESOR_ID,$idP);
    $this->addSortCriteria($c);
    $this->addFiltersCriteria($c);
    $this->pager->setCriteria($c);
    $this->pager->setPage($this->getRequestParameter('page', 1));
    $this->pager->init();
  }

  public function executeCreate()
  {
    return $this->forward('estudiantesasignados', 'edit');
  }

  public function executeSave()
  {
    return $this->forward('estudiantesasignados', 'edit');
  }

  public function executeEdit()
  {
    $this->asignar_est = $this->getAsignarEstOrCreate();

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      $this->updateAsignarEstFromRequest();

      $this->saveAsignarEst($this->asignar_est);

      $this->setFlash('notice', 'Your modifications have been saved');

      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('estudiantesasignados/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('estudiantesasignados/list');
      }
      else
      {
        return $this->redirect('estudiantesasignados/edit?id='.$this->asignar_est->getId());
      }
    }
    else
    {
      $this->labels = $this->getLabels();
    }
  }

  public function executeDelete()
  {
    $this->asignar_est = AsignarEstPeer::retrieveByPk($this->getRequestParameter('id'));
    $this->forward404Unless($this->asignar_est);

    try
    {
      $this->deleteAsignarEst($this->asignar_est);
    }
    catch (PropelException $e)
    {
      $this->getRequest()->setError('delete', 'Could not delete the selected Asignar est. Make sure it does not have any associated items.');
      return $this->forward('estudiantesasignados', 'list');
    }

    return $this->redirect('asignarestudiante/list');
  }

  public function handleErrorEdit()
  {
    $this->preExecute();
    $this->asignar_est = $this->getAsignarEstOrCreate();
    $this->updateAsignarEstFromRequest();

    $this->labels = $this->getLabels();

    return sfView::SUCCESS;
  }

  protected function saveAsignarEst($asignar_est)
  {
    $asignar_est->save();

  }

  protected function deleteAsignarEst($asignar_est)
  {
    $asignar_est->delete();
  }

  protected function updateAsignarEstFromRequest()
  {
    $asignar_est = $this->getRequestParameter('asignar_est');

    if (isset($asignar_est['estudiante_id']))
    {
    $this->asignar_est->setEstudianteId($asignar_est['estudiante_id'] ? $asignar_est['estudiante_id'] : null);
    }
    if (isset($asignar_est['profesor_id']))
    {
    $this->asignar_est->setProfesorId($asignar_est['profesor_id'] ? $asignar_est['profesor_id'] : null);
    }
  }

  protected function getAsignarEstOrCreate($id = 'id')
  {
    if (!$this->getRequestParameter($id))
    {
      $asignar_est = new AsignarEst();
    }
    else
    {
      $asignar_est = AsignarEstPeer::retrieveByPk($this->getRequestParameter($id));

      $this->forward404Unless($asignar_est);
    }

    return $asignar_est;
  }

  protected function processFilters()
  {
  }

  protected function processSort()
  {
    if ($this->getRequestParameter('sort'))
    {
      $this->getUser()->setAttribute('sort', $this->getRequestParameter('sort'), 'sf_admin/asignar_est/sort');
      $this->getUser()->setAttribute('type', $this->getRequestParameter('type', 'asc'), 'sf_admin/asignar_est/sort');
    }

    if (!$this->getUser()->getAttribute('sort', null, 'sf_admin/asignar_est/sort'))
    {
    }
  }

  protected function addFiltersCriteria($c)
  {
  }

  protected function addSortCriteria($c)
  {
    if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/asignar_est/sort'))
    {
      $sort_column = AsignarEstPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
      if ($this->getUser()->getAttribute('type', null, 'sf_admin/asignar_est/sort') == 'asc')
      {
        $c->addAscendingOrderByColumn($sort_column);
      }
      else
      {
        $c->addDescendingOrderByColumn($sort_column);
      }
    }
  }

  protected function getLabels()
  {
    return array(
      'asignar_est{id}' => 'Id:',
      'asignar_est{estudiante_id}' => 'Estudiante:',
      'asignar_est{profesor_id}' => 'Profesor:',
    );
  }
}
